package eu.telecombretagne.rsm.gui.frames.objects;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

public class AutomateCircleState {
	
	private Integer centerX, centerY, radius;
	private Color firstColor, secondColor, thirdColor, titleColor;
	private String title;
	private Boolean firstRing = false;
	private Boolean secondRing = false;
	
	/**
	 * The constructor of the AutomateCircleState.
	 * 
	 * @param pCenterX An X coordinate of the center of the circle.
	 * @param pCenterY An Y coordinate of the center of the circle.
	 * @param pRadius A radius of the circle.
	 * @param pFirstColor A value of the first color.
	 * @param pSecondColor A value of the second color.
	 * @param pThirdColor A value of the third color.
	 * @param pTitleColor A color of the title.
	 * @param pTitle A title string.
	 */
	public AutomateCircleState(Integer pCenterX, Integer pCenterY, Integer pRadius, 
			Color pFirstColor, Color pSecondColor, Color pThirdColor, Color pTitleColor, String pTitle){
		
		centerX = pCenterX;
		centerY = pCenterY;
		radius = pRadius;
		
		firstColor = pFirstColor;
		secondColor = pSecondColor;
		thirdColor = pThirdColor;
		titleColor = pTitleColor;
		
		title = pTitle;
	}
	
	/**
	 * Performs a drawing action.
	 * @param g A Graphics object.
	 */
	public void draw(Graphics g){
		Graphics2D g2 = (Graphics2D) g;
		
		Ellipse2D.Float firstEllipse = new Ellipse2D.Float(centerX - radius, centerY - radius, radius * 2, radius * 2);
		Ellipse2D.Float secondEllipse = new Ellipse2D.Float(firstEllipse.x +3, firstEllipse.y +3, firstEllipse.width -6, firstEllipse.height -6);
		Ellipse2D.Float thirdEllipse = new Ellipse2D.Float(firstEllipse.x +6, firstEllipse.y +6, firstEllipse.width -12, firstEllipse.height -12);
		
		if(firstRing){
			g2.setColor(firstColor);
			g2.fill(firstEllipse);
		}
		
		if(secondRing){
			g2.setColor(secondColor);
		} else {
			g2.setColor(thirdColor);
		}
		g2.fill(secondEllipse);
		
		g2.setColor(thirdColor);
		g2.fill(thirdEllipse);
		
		drawTitle(g2);
	}
	
	private void drawTitle(Graphics2D g){
		FontMetrics fontMetrics  = g.getFontMetrics();
		Rectangle2D stringBounds = fontMetrics.getStringBounds(title, g);
		Float centerFX = (float) stringBounds.getCenterX();
		Float centerFY = (float) stringBounds.getCenterY();
		
		g.setColor(titleColor);
		g.drawString(title, centerX - centerFX, centerY - centerFY);
	}
	
	/**
	 * Sets the first circle visible.
	 * 
	 * @param pVisible If set to <i>true</i> the first circle is visible.
	 */
	public void setFirstRingVisible(Boolean pVisible){
		firstRing = pVisible;
	}
	
	/**
	 * Sets the second circle visible.
	 * 
	 * @param pVisible If set to <i>true</i> the second circle is visible.
	 */
	public void setSecondRingVisible(Boolean pVisible){
		secondRing = pVisible;
	}
}